package web.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import spider.entitys.Novel;
import web.mapper.NovelMapper;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * created by yb
 * on 2017/8/19.
 **/
@Service
public class NovelServiceImpl implements NovelService {
    @Resource
    private NovelMapper mapper;
    /**
     * 通过关键词从数据库中找数据,返回想要的内容
     *
     * @param keyword 关节次
     * @return 数据库中的结果
     */
    @Override
    public PageInfo< Novel >  getNovelByKeyWord( String keyword,Integer page,Integer rows ) {
        keyword = "%" + keyword + "%";
        PageHelper.startPage(page,rows);
        List< Novel > list = mapper.getNovelByKeyWord( keyword );
        return new PageInfo<>( list );
    }

    @Override
    public List< Novel > getNovelByKeyWord( String keyword, int platformId ) {
        Map<String,String> map = new HashMap<>(  );
        map.put( "keyword", "%" + keyword + "%");
        map.put( "platformId", platformId+"");
        return mapper.getNovelByKeyWord2( map);
    }
}
